//
//  MyViewController.m
//  家校互通
//
//  Created by 姬鑫宇 on 15/5/11.
//  Copyright (c) 2015年 姬鑫宇. All rights reserved.
//

#import "MyViewController.h"
#import "MyViewTableViewCell.h"

#import "PostionListViewController.h"
#import "MyHeaderViewCell.h"
#import "MyInformationViewController.h"
#import "PayViewController.h"
#import "ChargeTuitionViewController.h"
#import "InviteFamilyMemberViewController.h"//邀请家庭成
#import "SettingsViewController.h"//设置
#import "LatestNewsViewController.h"//资讯
#import "MyCollectMsgViewController.h"//收藏
#import "LeaveMessageListViewController.h"//请假条列表

@interface MyViewController ()<UITableViewDataSource,UITableViewDelegate>
{
    NSArray *titleArray;
    NSArray *imageArray;
}
@end

@implementation MyViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _contentTableView.delegate=self;
    _contentTableView.dataSource=self;
    if ([DSFUserInfo shareUserInstance].isTeachLogin) {
        titleArray = [[NSArray alloc]initWithObjects:@"收藏",@"资讯",@"请假条",@"手环定位",@"收费",@"设置", nil];
        imageArray = [[NSArray alloc]initWithObjects:[UIImage imageNamed:@"收藏"],[UIImage imageNamed:@"资讯"],[UIImage imageNamed:@"请假条1"],[UIImage imageNamed:@"定位"],[UIImage imageNamed:@"收费"],[UIImage imageNamed:@"设置"], nil];
    }else
    {
        titleArray = [[NSArray alloc]initWithObjects:@"邀请家庭成员",@"收藏",@"资讯",@"请假条",@"钱包",@"设置", nil];
        imageArray = [[NSArray alloc]initWithObjects:[UIImage imageNamed:@"邀请家庭成员"],[UIImage imageNamed:@"收藏"],[UIImage imageNamed:@"资讯"],[UIImage imageNamed:@"请假条1"],[UIImage imageNamed:@"钱包"],[UIImage imageNamed:@"设置"], nil];
    }
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadView) name:kReloadMyInfo object:nil];
    // Do any additional setup after loading the view.
}

- (void)reloadView{
    [_contentTableView reloadData];
}

- (void)viewDidDisappear:(BOOL)animated{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

#pragma mark -UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if ( [DSFUserInfo shareUserInstance].isTeachLogin) {
        switch (section) {
            case 1:
                return 3;
                break;
            default:
                return 1;
                break;
        }
    }else
    {
        switch (section) {
            case 2:
                return 3;
                break;
            default:
                return 1;
                break;
        }
    }
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section==0) {
        MyHeaderViewCell *vCell=[tableView dequeueReusableCellWithIdentifier:@"MyHeaderViewCell" forIndexPath:indexPath];
        UIView *selectView=[[UIView alloc]initWithFrame:vCell.frame];
        selectView.backgroundColor=COLOR(240, 240, 240);
        vCell.selectedBackgroundView=selectView;
//        [vCell.imgForHeader sd_setImageWithURL:[NSURL URLWithString:[DSFUserInfo shareUserInstance].icon] placeholderImage:[UIImage imageNamed:@"icon01.jpg"]];
        return vCell;
    }else
    {
        MyViewTableViewCell *vCell=[tableView dequeueReusableCellWithIdentifier:@"MyViewTableViewCell" forIndexPath:indexPath];
        UIView *selectView=[[UIView alloc]initWithFrame:vCell.frame];
        selectView.backgroundColor=COLOR(240, 240, 240);
        vCell.selectedBackgroundView=selectView;
        if ([DSFUserInfo shareUserInstance].isTeachLogin) {
            
            switch (indexPath.section) {
                case 1:
                    [vCell cellContentWithTitle:[titleArray objectAtIndex:indexPath.row] andImage:[imageArray objectAtIndex:indexPath.row]];
                    break;
                default:
                    [vCell cellContentWithTitle:[titleArray objectAtIndex:indexPath.row+1+indexPath.section] andImage:[imageArray objectAtIndex:indexPath.row+1+indexPath.section]];
                    break;
            }
        }else
        {
            switch (indexPath.section) {
                case 1:
                    [vCell cellContentWithTitle:[titleArray objectAtIndex:indexPath.row] andImage:[imageArray objectAtIndex:indexPath.row]];
                    break;
                case 2:
                    [vCell cellContentWithTitle:[titleArray objectAtIndex:indexPath.row+1] andImage:[imageArray objectAtIndex:indexPath.row+1]];
                    break;
                default:
                    [vCell cellContentWithTitle:[titleArray objectAtIndex:indexPath.row+indexPath.section+1] andImage:[imageArray objectAtIndex:indexPath.row+1+indexPath.section]];
                    break;
            }
        }
        return vCell;
    }
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 5;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    return nil;
}
#pragma mark -UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 10;
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.001;
}
// Called after the user changes the selection.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section==0) {
        //个人详情页面
        MyInformationViewController *vc = [self.storyboard  instantiateViewControllerWithIdentifier:@"MyInformationViewController"];
        
        AppDelegate *_appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
        [_appDelegate.mainViewController.navigationController pushViewController:vc animated:YES];
    }
    else
    {
        AppDelegate *_appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
        MyViewTableViewCell *vCell=(MyViewTableViewCell *)[tableView cellForRowAtIndexPath:indexPath];
        NSLog(@"%@",vCell.lbForTitle.text) ;
        if ([vCell.lbForTitle.text isEqualToString:@"手环定位"]) {
            PostionListViewController *vc = [self.storyboard  instantiateViewControllerWithIdentifier:@"PostionListViewController"];
            
           
            [_appDelegate.mainViewController.navigationController pushViewController:vc animated:YES];

        }else if ([vCell.lbForTitle.text isEqualToString:@"收费"]||[vCell.lbForTitle.text isEqualToString:@"钱包"]) {
            ChargeTuitionViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"ChargeTuitionViewController"];            
            
            [_appDelegate.mainViewController.navigationController pushViewController:vc animated:YES];
            
        }else if ([vCell.lbForTitle.text isEqualToString:@"邀请家庭成员"]) {
            InviteFamilyMemberViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"InviteFamilyMemberViewController"];
            
            [_appDelegate.mainViewController.navigationController pushViewController:vc animated:YES];
            
        }else if ([vCell.lbForTitle.text isEqualToString:@"请假条"]) {
            
            LeaveMessageListViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"LeaveMessageListViewController"];
            vc.title=@"请假条";
            [_appDelegate.mainViewController.navigationController pushViewController:vc animated:YES];
            
        }else if ([vCell.lbForTitle.text isEqualToString:@"设置"]) {
            SettingsViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"SettingsViewController"];
            
            [_appDelegate.mainViewController.navigationController pushViewController:vc animated:YES];
        }else if ([vCell.lbForTitle.text isEqualToString:@"收藏"]) {
            MyCollectMsgViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"MyCollectMsgViewController"];
            vc.title=@"收藏";
            [_appDelegate.mainViewController.navigationController pushViewController:vc animated:YES];
        }else if ([vCell.lbForTitle.text isEqualToString:@"资讯"]) {
            LatestNewsViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"LatestNewsViewController"];
            vc.title=@"资讯";
            [_appDelegate.mainViewController.navigationController pushViewController:vc animated:YES];
        }

    }
    [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
//    if (indexPath.section == 2) {
//        if (indexPath.row == 0) {
//        }
//    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
